home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 72 / IOPROG_72.ISO / soft / Codice / Web Application in Java / eLisa / Java Web App / support / src / CategorieProdotto.java next >
Encoding:
Java Source  |  2003-07-02  |  1.4 KB  |  46 lines

  1.  
  2. import java.sql.*;
  3.  
  4. public class CategorieProdotto extends TabellaDB {
  5.     
  6.     public CategorieProdotto( Connection conn ) {
  7.         super(conn);
  8.     }
  9.     
  10.     void drop() throws SQLException {
  11.         String sql = "DROP TABLE CATEGORIE_PRODOTTO";
  12.         execute( sql );
  13.     }
  14.     
  15.     void create() throws SQLException {
  16.         String sql = "CREATE TABLE CATEGORIE_PRODOTTO ( " +
  17.                         "ID int(11) NOT NULL auto_increment, "+
  18.                         "CODICE int(11) NOT NULL, "+
  19.                         "DESCRIZIONE varchar(100) NOT NULL default '', "+
  20.                         "PRIMARY KEY  (ID)"+
  21.                      ")";
  22.         execute( sql );
  23.     }
  24.     
  25.     void fill() throws SQLException {
  26.         String sql = "INSERT INTO CATEGORIE_PRODOTTO ( CODICE, DESCRIZIONE ) VALUES (?,?)";
  27.         int[] codici = { 10, 11, 12 };
  28.         String[] categorie = { "Libri", "DVD", "CD Musicali" };
  29.         
  30.         PreparedStatement pstmt = conn.prepareStatement( sql );
  31.         
  32.         for( int i=0; i<categorie.length; i++ ) {
  33.             int pos = 1;
  34.             
  35.             pstmt.setInt( pos++, codici[ i ] );
  36.             pstmt.setString( pos++, categorie[ i ] );
  37.             
  38.             log( "CategorieProdotto: "+codici[ i ]+", "+categorie[ i ] );
  39.             
  40.             pstmt.executeUpdate();
  41.         }
  42.         pstmt.close();
  43.     }
  44.  
  45. }
  46.